package net.sx.minemodule;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.homegoods.area.model.SubModelList;
import com.homegoods.classify.model.Constant;
import com.homegoods.resource.HomeGoodsApp;
import com.network.retrofit_rx.Api.ActionSubscriber;
import com.network.retrofit_rx.Api.CommandImpl;
import com.network.retrofit_rx.Api.HttpManager;

import net.sx.minemodule.mvp.bean.CheckRequestImg;
import net.sx.minemodule.mvp.bean.FeedBackParams;
import net.sx.minemodule.mvp.bean.LogisticsCompany;
import net.sx.minemodule.mvp.bean.OrderListDetailBean;
import net.sx.minemodule.mvp.bean.OrderSalesReqBean;
import net.sx.minemodule.mvp.bean.RefundBean;
import net.sx.minemodule.mvp.bean.UpdatePwdParams;
import net.sx.minemodule.mvp.model.BrokerageInfoModel;
import net.sx.minemodule.mvp.model.CommissionInfoModel;
import net.sx.minemodule.mvp.model.MineIntegralModel;
import net.sx.minemodule.mvp.model.MineMedalInfoModel;

import org.json.JSONObject;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author ch
 * @ClassName: ApiUtil
 * @date 2018/11/27
 */
public class MineApiUtils {
    /**
     * 修改用户信息
     *
     * @param fieldName  要修改的信息名称
     * @param fieldValue 信息内容
     * @param error
     */
    public static void modifyUserInfo(String fieldName, String fieldValue, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CLIENT_UPD)
                .addParams("token", HomeGoodsApp.getToken())
                .addField(fieldName, fieldValue)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().postUrlForQuery(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 修改用户手机号,修改登录密码，修改支付密码
     *
     * @param error
     */
    //del shibo.zheng start
    /*public static void modifyUserPhoneAndPwd(String fieldeName, String fieldValue, String code, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CLIENT_UPD)
                .addParams("token", HomeGoodsApp.getToken())
                .addField(fieldeName, fieldValue)
                .addField("SMSCode", code)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().postUrlForQuery(command, new ActionSubscriber<>(consumer, error, null));
    }*/   //del shibo.zheng end
    //add shibo.zheng start
    public static void modifyUserPhoneAndPwd(UpdatePwdParams params, Consumer<String> consumer, Consumer<Throwable> error) {
        HttpManager.getInstance().post(Constant.SERVER_URL + Constant.CLIENT_UPD,
                JSON.toJSONString(params),
                Constant.TOKENHEAD + HomeGoodsApp.getToken(),
                new ActionSubscriber<>(consumer, error, null),
                String.class);
    }
    //add shibo.zheng end

    /**
     * 文件上传前上报
     *
     * @param error lockid=200
     *              filesize=102400
     *              filename=829095120.jpg
     *              md5=35f48d1c5770e6cfc2916d5c13f23ba7
     *              usid=partner_087de3fe984a464a93199390f1edc9ee
     */
    public static void postKDSFile(String md5, String fileName, long fileSize, String usid, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.AFU_KDSFFILE)
                .addParams("lockid", usid)
                .addParams("filesize", fileSize)
                .addParams("filename", fileName)
                .addParams("md5", md5)
                .addParams("usid", usid)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 文件上传数据体
     *
     * @param error --md5=35f48d1c5770e6cfc2916d5c13f23ba7--（文件md5值）
     *              必选项--tag=QQ图片20160905135128.jpg--（文件名）
     *              必选项--cmd=身份证图片--（文件描述）
     *              必选项--cls=附件应用--（分类）
     *              必选项--file=文件对象--（文件对象）
     */
    public static void postFile(String md5, String fileName, File file, Consumer<String> consumer, Consumer<Throwable> error) {
        Map<String, RequestBody> map = new HashMap<>();
        map.put("cmd", addParameter("头像"));
        map.put("cls", addParameter("附件应用》用户上传 》形像照片"));
        map.put("tag", addParameter(fileName));
        map.put("file\";  filename=\"" + file.getName(), addParameter(file));
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.AFU_KDSFFILE)
                .addParams("md5", md5)
                .putBodys(map)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().uploadfile(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 上传售后图片
     *
     * @param item
     * @param consumer
     * @param error
     */
    public static void postFile(CheckRequestImg item, Consumer<String> consumer, Consumer<Throwable> error) {
        Map<String, RequestBody> map = new HashMap<>();
        map.put("image\";  filename=\"" + item.getFile().getName(), addParameter(item.getFile()));
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.POST_FILE_AFTER_SALE_UP_IMG)
                .putBodys(map)

                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().uploadfile(command, new ActionSubscriber<>(consumer, error, null));
    }

    public static RequestBody addParameter(Object o) {
        RequestBody body = null;
        if (o instanceof String) {
            body = RequestBody.create(MediaType.parse("multipart/form-data"), (String) o);
        } else if (o instanceof File) {
            body = RequestBody.create(MediaType.parse("multipart/form-data;charset=UTF-8"), (File) o);
        }
        return body;
    }

    /**
     * 获取我的收藏列表，商品收藏列表
     * token=b230e22fcf634cf8afb63e52bdf     //登录令牌
     * BindType=LoveCommodity                //统计收藏类别
     * BOWay=self$all
     * psize=50
     * pos=1
     */
    public static void getMyCollectionGoodsList(int pos, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLIST_CENTER)
                .addParams("AppType", "commodity_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("BindType", "LoveCommodity")
                .addParams("BOWay", "self")
                .addParams("pos", pos)
                .addParams("psize", "20")
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取商品收藏列表
     * add shibo.zheng
     */
    public static void getCollectionList(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_COLLECTION_LIST + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 根据商品id删除某条收藏商品
     */
    public static void delCollectionById(int productId, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DEL_COLLECTION_BYID + "/" + productId)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的收藏，设计师收藏列表
     *
     * @param error AppType=Mystylist_  //方法名 Bytype后面接接1获取商品收藏列表
     *              outdata=jsonlist       //数据返回格式
     *              token= pp              //用户token验证
     */
    public static void getMyCollectionStylistList(Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLISTCENTER)
                .addParams("AppType", "Mystylist_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的收藏，设计师收藏列表
     *
     * @param error AppType=Mystylist_  //方法名 Bytype后面接接1获取商品收藏列表
     *              outdata=jsonlist       //数据返回格式
     *              token= pp              //用户token验证
     *              TODO
     */
    public static void getMyCollectionVideo(Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLISTCENTER)
                .addParams("AppType", "Mystylist_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 描述:获取我的订单列表
     * author:胡邦茂
     * CreateDate: 2019/7/5 19:52
     *
     * @param type
     * @param page
     * @param size
     */
    public static void getMyOrderList(int type, int page, int size, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_MY_ORDER_LIST + type + "/" + page + "/" + size)
                /*.addParams("cmd", "OrderList")
                .add("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsondata")
                .addParams("type", type)*/
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 描述:获取订单申请 售后信息
     * author:胡邦茂
     * CreateDate: 2019/7/11 14:59
     *
     * @param orderID
     */
    public static void getOrderAfterSale(int orderID, Consumer<OrderSalesReqBean> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_ORDER_AFTER_SALE + orderID)
                .setObject(true)
                .setClass(OrderSalesReqBean.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 描述:提交本次售后
     * author:胡邦茂
     * CreateDate: 2019/7/11 14:59
     *
     * @param map
     */
    public static void orderAfterCommit(HashMap<String, Object> map, Consumer<String> consumer, Consumer<Throwable> error) {
        Log.e("hbm", "memberAfterSaleResult=" + JSON.toJSON(map).toString());
        HttpManager.getInstance().post(Constant.SERVER_URL + Constant.GET_ORDER_AFTER_COMMIT,
                JSON.toJSONString(map),
                Constant.TOKENHEAD + HomeGoodsApp.getToken(),
                new ActionSubscriber<>(consumer, error, null),
                String.class);

    }

    /**
     * 描述:  订单商品Id查询物流信息
     * author:胡邦茂
     * CreateDate: 2019/7/13 9:47
     *
     * @param orderProductId
     */
    public static void orderLogisticsLoad(int orderProductId, Consumer<OrderSalesReqBean> consumer, Consumer<Throwable> error) {
        CommandImpl.Builder command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.POST_ORDER_GET_LOGISTICS)
                .addParams("orderProductId", orderProductId)
                .setObject(true)
                .setClass(OrderSalesReqBean.class);

        HttpManager.getInstance().post(command.create(), new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 描述:取消订单
     * author:胡邦茂
     * CreateDate: 2019/7/5 19:52
     *
     * @param orderId   订单ID
     * @param type      1 操作有误 2重复下单/下错单 3我不想买了 10 其他原因
     * @param otherText 其他备注
     */
    public static void clearMyOrder(int orderId, int type, String otherText, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_CLEAR_MY_ORDER)
                .addField("orderId", orderId)
                .addField("cancelType", type)
                .addField("remark", otherText)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 描述:获取客服电话
     * author:胡邦茂
     * CreateDate: 2019/7/5 19:52
     *
     * @param orderId
     * @param consumer
     * @param error
     */
    public static void getServicePhoneNumber(int orderId, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_ORDER_SERVICE_PHONENUMBER + orderId)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 描述:  确认收货
     * author:胡邦茂
     * CreateDate: 2019/7/5 19:52
     *
     * @param orderId 订单号
     * @param type    类型
     */
    public static void obtainGoods(int orderId, int type, Consumer<Integer> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_OBTAIN_MY_ORDER + orderId)
                .setObject(true)
                .setClass(Integer.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的订单列表
     *
     * @param error AppType=RefundList_ //固定传RefundList_
     *              token=0000              //传用户的token
     *              outdata=jsonlist         //数据输出方式
     */
    public static void getRefundList(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        //改原请求框架代价较大啊，这样开销最小了吧
        String path =  Constant.AFTER_ORDER_LIST;
        path = putPathParam(path, "pageNum", "" + pageNum);
        path = putPathParam(path, "pageSize", "" + pageSize);
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + path)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }


    /**
     * 获取我的收藏列表，商品收藏列表
     *
     * @param error cmd=Modification   //方法名
     *              out=jsonlist       //数据传输方式
     *              type=3            //type固定传3，不能传别的
     *              sid=ppp          //收藏的sid
     */
    public static void removeMyCollectionGoods(String sid, Consumer<Object> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.REMOVE_COLLECTION)
                .addParams("cmd", "Modification")
                .addParams("sid", sid)
                .addParams("type", "3")
                .addParams("out", "jsonlist")
                .setObject(true)
                .setClass(Object.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的收益
     *
     * @param error cmd=MyIncome    //方法名固定传MyIncome
     *              token=000       //token身份验证
     *              outdata=jsondata //数据输出方式
     */
    public static void getYidlds(Consumer<Object> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.SIMPLE_PLAN_CMD)
                .addParams("cmd", "MyIncome")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsondata")
                .setObject(true)
                .setClass(Object.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的收益记录列表
     *
     * @param error AppType=EarningsList_  //EarningsList_固定传
     *              token=00000     //用户token令牌
     *              outdata=jsonlist  //数据输出方式
     */
    public static void getEarningsList(Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLISTCENTER)
                .addParams("AppType", "EarningsList_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的邀请列表
     *
     * @param error AppType=Myinvite_  //固定传Myinvite_
     *              token=000          //传用户身份token
     *              outdata=jsonlist   //数据输出方式
     */
    public static void getMyinviteList(Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLISTCENTER)
                .addParams("AppType", "Myinvite_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 添加订单
     *
     * @param error 参数名=参数值    //是否必选项及意义描述
     *              cmd=Orderadd         //指定某个方法
     *              outdata=jsonlist     //排序方式
     *              Addresid=888         //地址的sid
     *              token=00             //token验证
     *              content=[{sid:'商品sid',serve:'上门服务',num:'商品数量',stadarry:'属性sid集合,传字符数组',argument:'属性的中文名称'}]         //商品参数拼接成json字符的数组
     *              paytype=alipay   //选择支付方式，alipay支付宝，weixin微信支付
     */
    public static void setOrder(String payType, String content, String addresId, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.SIMPLE_PLAN_CMD)
                .addParams("cmd", "Orderadd")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .addParams("Addresid", addresId)
                .addParams("content", content)
                .addParams("paytype", payType)
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的提现列表
     * AppType=WithdrawalList_  //固定传WithdrawalList_
     * token=0000              //传用户的token
     * outdata=jsonlist         //数据输出方式
     * Type=0       //0:一月，1：三月，2：半年 不传：一个星期
     */
    public static void getwithDrawList(String type, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLISTCENTER)
                .addParams("AppType", "WithdrawalList_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .addParams("Type", type)
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 提交 提现
     *
     * @param error cmd=RequestWithdrawal  //固定传RequestWithdrawal
     *              token=000           //用户token身份
     *              money=9             //提现金额
     *              type=0      //提现方式  0微信，1支付宝，2银行卡
     *              account=kkkk   //收款账号
     */
    public static void toWithDraw(String money, String type, String bank, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.SIMPLE_PLAN_CMD)
                .addParams("cmd", "RequestWithdrawal")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("money", money)
                .addParams("type", type)
                .addParams("account", bank)
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的粉丝列表
     * AppType=Myfans_         //固定
     * token=111
     * outdata=jsonlist
     */
    public static void getMyFansList(Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.DLISTCENTER)
                .addParams("AppType", "Myfans_")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("outdata", "jsonlist")
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 添加商品评价
     * AppType=Myfans_         //固定
     * token=111
     * outdata=jsonlist TODO
     */
    public static void pushScore(Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.AMAPI_AGMESSAGE)
                .addParams("cmd", "adit")
                .addParams("token", HomeGoodsApp.getToken())
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
        HttpManager.getInstance().postUrlForQuery(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取我的粉丝列表
     * cmd=ApplySales         //固定传ApplySales
     * token=aaaa             //用户token
     * ordersid=aabb          //订单的sid
     */
    public static void getApplySales(String ordersid, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.REMOVE_COLLECTION)
                .addParams("cmd", "ApplySales")
                .addParams("token", HomeGoodsApp.getToken())
                .addParams("ordersid", ordersid)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 发送短信验证码(已经注册后使用)
     *
     * @param phone
     * @return
     */
    public static void getCaptchaForForgetPassWord(String phone, Consumer<JSONObject> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CLIENT_SEND_VERIFYCODE)
//                .addParams("telphone", phone) //正式参数，验证码使用/sso/send/verifycode参数时用
                .addParams("telephone", phone)  //临时参数，验证码使用/sso/authcode参数时使用
                .setObject(true)
                .setClass(JSONObject.class)
                .create();
//        HttpManager.getInstance().post(command, new ActionSubscriber<>(consumer, error, null));
        HttpManager.getInstance().get(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 退出登录
     * @param consumer
     * @param error
     */
    public static void logout(Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(/*Constant.SERVER_URL + Constant.LOGOUT*/"http://192.168.3.133:8443/logout")
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().post(command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取历史积分记录
     * @param consumer
     * @param error
     */
    public static void getHistoryIntegral(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.HISTORY_INTEGRAL + "/" +pageNum + "/" + pageSize)
                .setClass(SubModelList.class)
                .setObject(true)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取积分记录界面我的积分数据
     * @param consumer
     * @param error
     */
    public static void getIntegralData(Consumer<MineIntegralModel> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.MINE_INTEGRAL_DATA)
                .setObject(true)
                .setClass(MineIntegralModel.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取积分明细接口
     * @param pageNum
     * @param pageSize
     * @param consumer
     * @param error
     */
    public static void getIntegralInfo(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.INTEGRAL_INFO + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取历史奖牌记录接口
     * @param pageNum
     * @param pageSize
     * @param consumer
     * @param error
     */
    public static void getHistoryMedal(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.HISTORU_MEDAL + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取个人奖牌信息
     * @param consumer
     * @param error
     */
    public static void getMedalInfo(Consumer<MineMedalInfoModel> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.MEDAL_INFO)
                .setObject(true)
                .setClass(MineMedalInfoModel.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取兑换商品列表
     * @param pageNum
     * @param pageSize
     * @param consumer
     * @param error
     */
    public static void getConvertList(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.CONVERT_LIST + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取个人奖牌明细
     * @param pageNum
     * @param pageSize
     * @param consumer
     * @param error
     */
    public static void getMedalList(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.MEDAL_LIST + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取个人提成界面信息
     * @param consumer
     * @param error
     */
    public static void getCommissionInfo(Consumer<CommissionInfoModel> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.COMMISSION_INFO)
                .setClass(CommissionInfoModel.class)
                .setObject(true)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取个人提成明细
     * @param consumer
     * @param error
     */
    public static void getCommissionList(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.COMMISSION_LIST + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取提成历史记录
     * @param consumer
     * @param error
     */
    public static void getHistoryCommission(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.HISTORY_COMMISSION + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取佣金界面个人佣金信息
     * @param consumer
     * @param error
     */
    public static void getBrokerageInfo(Consumer<BrokerageInfoModel> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.BROKERAGE_INFO)
                .setObject(true)
                .setClass(BrokerageInfoModel.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取佣金明细
     * @param pageNum
     * @param pageSize
     * @param consumer
     * @param error
     */
    public static void getBrokerageList(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.BROKERAGE_LIST + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取历史佣金记录
     * @param pageNum
     * @param pageSize
     * @param consumer
     * @param error
     */
    public static void getHistoryBrokerage(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.HISTROY_BROKERAGE + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    public static void getShoppingCart(int pageNum, int pageSize, Consumer<SubModelList> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.SHOPPING_CAR + "/" + pageNum + "/" + pageSize)
                .setObject(true)
                .setClass(SubModelList.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 获取订单详情
     * author: Norton
     * @param orderId
     * @param consumer
     * @param error
     */
    public static void getOrderDetail(String orderId ,Consumer<OrderListDetailBean> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.ORDER_DETAIL + "/" + orderId )
                .setObject(true)
                .setClass(OrderListDetailBean.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 描述:取消订单
     * author:Norton
     * CreateDate: 2019/7/5 19:52
     *
     * @param orderId   订单ID
     * @param type      1 操作有误 2重复下单/下错单 3我不想买了 10 其他原因
     */
    public static void cancelOrder(String orderId, String type, Consumer<String> consumer, Consumer<Throwable> error) {
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + Constant.GET_CANCEL_ORDER + "/" + type + "/" + orderId)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 退款/售后 详情
     * @param returnApplyId 售后订单id
     */
    public static void getRefundInfo(String returnApplyId, Consumer<RefundBean> consumer, Consumer<Throwable> error) {
        String path =  Constant.AFTER_ORDER_DETAIL;
        path = putPathParam(path, "id", returnApplyId);
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + path)
                .setObject(true)
                .setClass(RefundBean.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }


    /**
     * 退款/售后  撤销售后申请
     * @param returnApplyId 售后订单id
     */
    public static void cancelRefundOrder(String returnApplyId, Consumer<String> consumer, Consumer<Throwable> error) {
        String path =  Constant.CANCEL_AFTER_ORDER;
        path = putPathParam(path, "returnApplyId", returnApplyId);
        CommandImpl command = new CommandImpl.Builder()
                .setUrl(Constant.SERVER_URL + path)
                .setObject(true)
                .setClass(String.class)
                .create();
        HttpManager.getInstance().get(Constant.TOKENHEAD + HomeGoodsApp.getToken(), command, new ActionSubscriber<>(consumer, error, null));
    }

    /**
     * 退款/售后  填写物流信息,确认售后订单
     */
    public static void ensureAfterOrder(LogisticsCompany data, Consumer<String> consumer, Consumer<Throwable> error) {
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("logisticsCompany",data.getName());
        jsonObject.put("logisticsSn",data.getOrderNumber());
        jsonObject.put("returnApplyId",data.getReturnApplyId());
        HttpManager.getInstance().post(Constant.SERVER_URL + Constant.MODIFY_AFTER_ORDER_LOGISTICS,
                JSON.toJSONString(jsonObject),
                Constant.TOKENHEAD + HomeGoodsApp.getToken(),
                new ActionSubscriber<>(consumer, error, null), String.class);
    }

    private static String putPathParam(String url, String key, String value) {
        return url.replace("{" + key + "}", value);

    }

    public static void feedBackSave(FeedBackParams params, Consumer<String> consumer, Consumer<Throwable> error) {
        HttpManager.getInstance().post(Constant.SERVER_URL + Constant.FEEDBACK_SAVE,
                JSON.toJSONString(params),
                Constant.TOKENHEAD + HomeGoodsApp.getToken(),
                new ActionSubscriber<>(consumer, error, null),
                String.class);
    }

}
